package com.start.common.tools;

import lombok.experimental.UtilityClass;

import java.util.Random;

@UtilityClass
public class UUIdTools {
    private static final SnowflakeIdWorker worker = new SnowflakeIdWorker(0, 0);

    public String createId32() {
        return creatId("", 32);
    }

    public static String creatId(String prefix, Integer digit) {
        if (digit == null) digit = 6;
        if (digit < 6) throw new RuntimeException("生成id位数不能小于6位");
        if (prefix == null) {
            prefix = "";
        }
        int tempNum = digit - prefix.length();
        if (tempNum < 0) throw new RuntimeException("超出范围");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < tempNum; i++) {
            int num = new Random().nextInt(9);
            sb.append(num);
        }
        return prefix  + sb.toString();
    }


    public static String createSnowFakeId() {
        return String.valueOf(worker.nextId());
    }
}
